package com.hopu.blb_erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hopu.blb_erp.entity.Order;
import com.hopu.blb_erp.entity.Settlement;
import com.hopu.blb_erp.entity.TShipping;
import com.hopu.blb_erp.service.OrderService;
import com.hopu.blb_erp.service.SettleService;
import com.hopu.blb_erp.service.ShippingService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
public class SettleController {

    @Autowired
    private SettleService settleService;

    @Autowired
    private OrderService orderService;
    @Autowired
    private ShippingService shippingService;

    @PostMapping("/settle")
    public ResponseEntity<String> addSettle(@RequestBody Settlement settlement){
        settleService.addSettle(settlement);
        TShipping shipping = shippingService.findByNumber(settlement.getFreightId());
        Order order = new Order();
        order.setOrderStatus("-4");
        orderService.update(order,new QueryWrapper<Order>().lambda().eq(Order::getOrderId,shipping.getOrderNumber()));
        return ResponseEntity.ok("ok");
    }
}
